package routers

import (
	"copper-cloud/middleware"
	v1 "copper-cloud/routers/api/v1"
	"github.com/gin-gonic/gin"
	"net/http"
)

func InitRouter() *gin.Engine {
	r := gin.New()

	r.Use(gin.Recovery())
	r.Use(middleware.Ginzap())

	// 不需要鉴权的接口
	//列表
	CopperCloudApi := r.Group("/api/copper-cloud")
	CopperCloudApi.Use()
	{
		CopperCloudApi.POST("/login", GetAuth)
		CopperCloudApi.GET("/auth/refreshToken", RefreshAuth)

		// file upload
		CopperCloudApi.POST("/upload", v1.AddFile)
		CopperCloudApi.StaticFS("/upload", http.Dir("upload"))
		CopperCloudApi.POST("/file/mark", v1.MarkFile)
	}

	// v1接口列表
	CopperCloudApiV1 := CopperCloudApi.Group("/v1")
	CopperCloudApiV1.Use(middleware.JWT())
	{
		CopperCloudApiV1.GET("/depts", v1.GetAllDepts)
		CopperCloudApiV1.GET("/dept/:dept_id", v1.GetDeptById)
		CopperCloudApiV1.POST("/dept", v1.AddDept)

		CopperCloudApiV1.GET("/roles", v1.GetAllRoles)
		CopperCloudApiV1.GET("/role/:role_id", v1.GetRoleById)
		CopperCloudApiV1.POST("/role", v1.AddRole)

		CopperCloudApiV1.GET("/apps", v1.GetApps)
		CopperCloudApiV1.GET("/app/:app_id", v1.GetApp)
		CopperCloudApiV1.GET("/app/:app_id/envs", v1.GetAppEnvs)
		CopperCloudApiV1.GET("/app/:app_id/env/:app_namespace", v1.GetAppEnv)

		CopperCloudApiV1.POST("/user", v1.AddUser)
	}
	return  r
}